import {
  add,
  deleteByIds,
  queryPageList,
  setTaskStatus,
  update,
  queryList,
  queryAuditTaskInfo,
  immediateExecuteTask
} from '@/services/sensitiveData/taskCenter';

export default {
  namespace: 'taskMngt',
  state: {
    dataqueryPageList: { dataList: [], pageNum: 0, pageSize: 0, totalCount: 0 },
    dataqueryList: [],
    dataqueryAuditTaskInfo: {},
  },

  effects: {
    // 新增执行策略管理
    *add({ payload }, { call, put }) {
      const response = yield call(add, payload);
      return response;
    },
    // 删除执行策略管理
    *deleteByIds({ payload }, { call, put }) {
      const response = yield call(deleteByIds, payload);
      return response;
    },
    // 查询执行策略管理列表(带分页)
    *queryPageList({ payload }, { call, put }) {
      const response = yield call(queryPageList, payload);
      yield put({
        type: 'savequeryPageList',
        payload: response.data || { dataList: [], pageNum: 0, pageSize: 0, totalCount: 0 },
      });
    },
    //启用停用任务
    *setTaskStatus({ payload }, { call, put }) {
      const response = yield call(setTaskStatus, payload);
      return response;
    },
    // 修改执行策略管理
    *update({ payload }, { call, put }) {
      const response = yield call(update, payload);
      return response;
    },
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryList, payload);
      yield put({
        type: 'savequeryList',
        payload: response.data ? response.data.dataList || [] : [],
      });
    },
    *queryAuditTaskInfo({ payload }, { call, put }) {
      const response = yield call(queryAuditTaskInfo, payload);
      yield put({
        type: 'savequeryAuditTaskInfo',
        payload: response.data || {},
      });
    },
    *immediateExecuteTask({ payload }, { call, put }) {
      const response = yield call(immediateExecuteTask, payload);
      return response;
    },
  },
  reducers: {
    savequeryPageList(state, { payload }) {
      return {
        ...state,
        dataqueryPageList: payload,
      };
    },
    savequeryList(state, { payload }) {
      return {
        ...state,
        dataqueryList: payload,
      };
    },
    savequeryAuditTaskInfo(state, { payload }) {
      return {
        ...state,
        dataqueryAuditTaskInfo: payload,
      };
    },
  },
};
